import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'dart:async';

class DatetimeDemo extends StatefulWidget {
  DatetimeDemo({Key key}) : super(key: key);

  @override
  _DatetimeDemoState createState() => _DatetimeDemoState();
}

class _DatetimeDemoState extends State<DatetimeDemo> {
  DateTime selectDate = DateTime.now();
  TimeOfDay selectTime = TimeOfDay(hour: 9, minute: 30);

  Future<void> _selectDateFunc() async {
    final DateTime getDate = await showDatePicker(
      context: context, 
      initialDate: selectDate, 
      firstDate: DateTime(1900), 
      lastDate: DateTime(2100),
    );

    if (getDate == null) return;

    setState(() {
      selectDate = getDate;
    });
  }

  Future<void> _selectTimeFunc() async {
    final TimeOfDay getTime = await showTimePicker(
      context: context, 
      initialTime: selectTime
    );

    if (getTime == null) return;

    setState(() {
      selectTime = getTime;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DatetimeDemo'),
        elevation: 0.0,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              InkWell(
                onTap: _selectDateFunc,
                child: Row(
                  children: <Widget>[
                    Text(DateFormat.yMMMMd().format(selectDate)),
                    Icon(Icons.arrow_drop_down)
                  ]
                )
              ),
              InkWell(
                onTap: _selectTimeFunc,
                child: Row(
                  children: <Widget>[
                    Text(selectTime.format(context)),
                    Icon(Icons.arrow_drop_down)
                  ]
                )
              ),
            ],
          )
        ],
      ),
    );
  }
}